<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>
  <div id="app">

    <h1>{{username}}</h1>

    <!-- <input type="text" v-model="username">

    <input type="text" v-bind:value="username" v-on:input="username=$event.target.value"> -->


    <custom-input :value="username" v-on:input="handleInput">


    </custom-input>
    <custom-input v-model="username"></custom-input>

  </div>




  <script>
    // 全局组件
    Vue.component('custom-input', {
      props: ['value'],
      template: `
      <input type="text"
      :value="value"
      @input="$emit('input',$event.target.value)"
      
      />`,
      data() {
        return {
          count: 0
        }
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {
        username: "hanye"
      },
      methods: {
        handleInput(val) {
          this.username = val;
        }
      }
    })




  </script>

</body>

</html>